package com.ruoyi.game.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.game.api.domin.GameUser;
import com.ruoyi.game.service.IGameUserService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 游戏用户Controller
 *
 * @author qidian
 * @date 2022-05-06
 */
@RestController
@RequestMapping("/player")
public class GameUserController extends BaseController
{
    @Autowired
    private IGameUserService gameUserService;

    /**
     * 查询游戏用户列表
     */
    @RequiresPermissions("game:player:list")
    @GetMapping("/list")
    public TableDataInfo list(GameUser gameUser)
    {
        startPage();
        List<GameUser> list = gameUserService.selectGameUserList(gameUser);
        return getDataTable(list);
    }

    /**
     * 导出游戏用户列表
     */
    @RequiresPermissions("game:player:export")
    @Log(title = "游戏用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GameUser gameUser)
    {
        List<GameUser> list = gameUserService.selectGameUserList(gameUser);
        ExcelUtil<GameUser> util = new ExcelUtil<GameUser>(GameUser.class);
        util.exportExcel(response, list, "游戏用户数据");
    }

    /**
     * 获取游戏用户详细信息
     */
    @RequiresPermissions("game:player:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gameUserService.selectGameUserById(id));
    }

    /**
     * 新增游戏用户
     */
    @RequiresPermissions("game:player:add")
    @Log(title = "游戏用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GameUser gameUser)
    {
        return toAjax(gameUserService.insertGameUser(gameUser));
    }

    /**
     * 修改游戏用户
     */
    @RequiresPermissions("game:player:edit")
    @Log(title = "游戏用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GameUser gameUser)
    {
        return toAjax(gameUserService.updateGameUser(gameUser));
    }

    /**
     * 删除游戏用户
     */
    @RequiresPermissions("game:player:remove")
    @Log(title = "游戏用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gameUserService.deleteGameUserByIds(ids));
    }

    /**
     * 初始化游戏用户
     */
    @InnerAuth
    @PostMapping("init")
    public R<Boolean> init(@RequestBody GameUser gameUser)
    {
        gameUserService.insertGameUser(gameUser);
        return R.ok();
    }
}
